<template>
  <div>
    <h1>Date 使用</h1>
    <!-- <el-button>改变数据</el-button> -->
    <el-input v-model="form.text"></el-input>

  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        text: "",
      }

    }
  },
  watch: {
    // text(newVal, oldVal) {
    //   console.log(newVal);
    // },
    'form.text': {
      handler(newVal, oldVal) {
        console.log(newVal);
      },
      immediate: true,
      deep: true
    },

  },
  created() {
    // this.getMinute(1700442262000, 1700442262000)
    let date = new Date("2023-11-21T08:01:35.861+00:00")

    console.log(date);
    var millisecondsValue = 3660000; // 示例毫秒值
    console.log(this.convertMilliseconds(millisecondsValue));
  },
  mounted() {
    // debugger

  },
  methods: {
    /**
     * 计算两个日期之间的分钟数
     */
    minutesDiff(dateTimeValue2, dateTimeValue1) {
      var differenceValue = (dateTimeValue2.getTime() - dateTimeValue1.getTime()) / 1000;
      differenceValue /= 60;
      return Math.abs(Math.round(differenceValue));
    },

    /**
     * 毫秒值转化为xx天xx小时xx分钟
     */
    convertMilliseconds(milliseconds) {
      var seconds = Math.floor((milliseconds / 1000) % 60);
      var minutes = Math.floor((milliseconds / (1000 * 60)) % 60);
      var hours = Math.floor((milliseconds / (1000 * 60 * 60)) % 24);
      var days = Math.floor(milliseconds / (1000 * 60 * 60 * 24));

      // return `${days}天 ${hours}小时 ${minutes}分`;
      return (days > 0 ? days + "天" : "") + (hours > 0 ? hours + "小时" : "") + (minutes > 0 ? minutes + "分钟" : "");
    }


  },
}
</script>

<style scoped>
</style>